package com.tianye.lc.activity;

import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.tianye.lc.R;
import com.tianye.lc.adapter.BreedRecyclerAdapter;
import com.tianye.lc.common.Final;

import java.util.List;

public class BreedActivity extends BaseActivity {
    private RecyclerView recycler;
    private BreedRecyclerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_breed);

        initTitle();
        initView();
        initData();

    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.title_tv);
        title.setText("Rose（月季、玫瑰、蔷薇）");
    }

    @Override
    protected int getTitleLayout() {
        return R.layout.title_view_2;
    }

    private void initView() {
        recycler = (RecyclerView) findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(this));
        recycler.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                //设定底部边距为1px
                outRect.set(0, 0, 0, 1);
            }
        });
        recycler.setHasFixedSize(true);

        adapter = new BreedRecyclerAdapter(this);
        recycler.setAdapter(adapter);

    }

    private void initData() {
        loadRoseFromNet();
    }

    private void loadRoseFromNet() {
        AVQuery<AVObject> query = new AVQuery<AVObject>(Final.ROSE);
        query.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> list, AVException e) {
                adapter.setData(list);
            }
        });
    }
}
